﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel;

namespace Test.Console
{
    public class Program
    {
        static void Main(string[] args)
        {
            // + Download
            // 1. prostor pro uchovavani informaci - napr. stazeno, ale nebylo nainstalovano atd. registr
            // 2. create new folder in temp to extract files to
            // 3. extrahovani souboru
            // spusteni - custom actions (pokud mozno, pouzit nejaky .NETovy interface)
            // kopirovani souboru (objekt FilesList)
            // kontrola souboru
            // commit nebo rollback -> custom actions
            // logovani (?)
            // dialogy


            // load file
            ZipExtractor ex = new ZipExtractor("", "");
            ex.ProgressChanged += new ProgressChangedEventHandler(ex_ProgressChanged);
            ex.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ex_RunWorkerCompleted);
            ex.RunWorkerAsync();

            System.Console.Read();
        }

        static int lastPercent = -1;

        static void ex_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (lastPercent != e.ProgressPercentage)
            {
                 System.Console.WriteLine(e.ProgressPercentage + "% complete");
                 lastPercent = e.ProgressPercentage;
            }
        }

        static void ex_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            System.Console.WriteLine("Done");
        }
    }

    public class ZipExtractor : BackgroundWorker
    {
        public ZipExtractor(string zipFilePath, string targetFolderPath)
        {

        }

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            double target = 1000000;

            for (int i = 0; i < target; i++)
            {
                this.OnProgressChanged(new ProgressChangedEventArgs((int)Math.Round((double)i / target * 100, 0), null));
                //Thread.Sleep(20);
            }

            //this.OnRunWorkerCompleted(new RunWorkerCompletedEventArgs(true, null, false));

        }
    }
}